/*    */ package blockbuster.components.motion;
/*    */ 
/*    */ import blockbuster.components.BedrockComponentBase;
/*    */ import blockbuster.components.IComponentParticleUpdate;
/*    */ import blockbuster.emitter.BedrockEmitter;
/*    */ import blockbuster.emitter.BedrockParticle;
/*    */ import blockbuster.math.molang.MolangException;
/*    */ import blockbuster.math.molang.MolangParser;
/*    */ import blockbuster.math.molang.expressions.MolangExpression;
/*    */ import com.google.gson.JsonArray;
/*    */ import com.google.gson.JsonElement;
/*    */ import com.google.gson.JsonObject;
/*    */ 
/*    */ public class BedrockComponentMotionDynamic
/*    */   extends BedrockComponentMotion implements IComponentParticleUpdate {
/* 16 */   public MolangExpression[] motionAcceleration = new MolangExpression[] { MolangParser.ZERO, MolangParser.ZERO, MolangParser.ZERO };
/* 17 */   public MolangExpression motionDrag = MolangParser.ZERO;
/* 18 */   public MolangExpression rotationAcceleration = MolangParser.ZERO;
/* 19 */   public MolangExpression rotationDrag = MolangParser.ZERO;
/*    */ 
/*    */ 
/*    */   
/*    */   public BedrockComponentBase fromJson(JsonElement elem, MolangParser parser) throws MolangException {
/* 24 */     if (!elem.isJsonObject()) return super.fromJson(elem, parser);
/*    */     
/* 26 */     JsonObject element = elem.getAsJsonObject();
/*    */     
/* 28 */     if (element.has("linear_acceleration")) {
/*    */       
/* 30 */       JsonArray array = element.getAsJsonArray("linear_acceleration");
/*    */       
/* 32 */       if (array.size() >= 3) {
/*    */         
/* 34 */         this.motionAcceleration[0] = parser.parseJson(array.get(0));
/* 35 */         this.motionAcceleration[1] = parser.parseJson(array.get(1));
/* 36 */         this.motionAcceleration[2] = parser.parseJson(array.get(2));
/*    */       } 
/*    */     } 
/*    */     
/* 40 */     if (element.has("linear_drag_coefficient")) this.motionDrag = parser.parseJson(element.get("linear_drag_coefficient")); 
/* 41 */     if (element.has("rotation_acceleration")) this.rotationAcceleration = parser.parseJson(element.get("rotation_acceleration")); 
/* 42 */     if (element.has("rotation_drag_coefficient")) this.rotationDrag = parser.parseJson(element.get("rotation_drag_coefficient"));
/*    */     
/* 44 */     return super.fromJson((JsonElement)element, parser);
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public JsonElement toJson() {
/* 50 */     JsonObject object = new JsonObject();
/* 51 */     JsonArray acceleration = new JsonArray();
/*    */     
/* 53 */     for (MolangExpression expression : this.motionAcceleration)
/*    */     {
/* 55 */       acceleration.add(expression.toJson());
/*    */     }
/*    */     
/* 58 */     object.add("linear_acceleration", (JsonElement)acceleration);
/*    */     
/* 60 */     if (!MolangExpression.isZero(this.motionDrag)) object.add("linear_drag_coefficient", this.motionDrag.toJson()); 
/* 61 */     if (!MolangExpression.isZero(this.rotationAcceleration)) object.add("rotation_acceleration", this.rotationAcceleration.toJson()); 
/* 62 */     if (!MolangExpression.isZero(this.rotationDrag)) object.add("rotation_drag_coefficient", this.rotationDrag.toJson());
/*    */     
/* 64 */     return (JsonElement)object;
/*    */   }
/*    */ 
/*    */ 
/*    */   
/*    */   public void update(BedrockEmitter emitter, BedrockParticle particle) {
/* 70 */     particle.acceleration.x += (float)this.motionAcceleration[0].get();
/* 71 */     particle.acceleration.y += (float)this.motionAcceleration[1].get();
/* 72 */     particle.acceleration.z += (float)this.motionAcceleration[2].get();
/* 73 */     particle.drag = (float)this.motionDrag.get();
/*    */     
/* 75 */     particle.rotationAcceleration += (float)this.rotationAcceleration.get() / 20.0F;
/* 76 */     particle.rotationDrag = (float)this.rotationDrag.get();
/*    */   }
/*    */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\motion\BedrockComponentMotionDynamic.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */